package com.mdd.front.controller.course;

import com.mdd.common.core.AjaxResult;
import com.mdd.front.LikeFrontThreadLocal;
import com.mdd.front.utils.SearchUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/course/search")
public class SearchController {

    @GetMapping("/list/get")
    public Object get() {
        LikeFrontThreadLocal.getUserId();
        List<String> history = SearchUtils.getSearchHistoryByUserId(LikeFrontThreadLocal.getUserId());
        return AjaxResult.success(history);
    }


    @GetMapping("/hot/list")
    public Object getHotList() {
        List<String> history = SearchUtils.getHotList(null);
        return AjaxResult.success(history);
    }

    @GetMapping("/list/clear")
    public Object clear() {
        SearchUtils.clearSearchHistory(LikeFrontThreadLocal.getUserId());
        return AjaxResult.success();
    }

}
